const jwt = require("jsonwebtoken");

const { PRIVATE_KEY, PUBLIC_KEY } = require("../app/config");

class LoginController {
  async login(ctx, next) {
    let { name, password } = ctx.request.body;
    // 显示登录成功 并返回token
    // 通过jwt和privatekey生成token
    const token = jwt.sign({ name, password }, PRIVATE_KEY, {
      expiresIn: 10 * 100000, //10s*1000 过期
      algorithm: "RS256", // 默认不写的话是 hs265 对称加密 现在是非对称
    });
    const status = 200;
    ctx.body = { data: { name, token }, meta: { status } };

    
  }
}

module.exports = new LoginController();
